package com.control;

import com.dbutil.UtilJdbc;
import com.entity.Push_work;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Date;
import java.util.List;

public class InsertWork extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String workName = req.getParameter("workName");
        String pushDate = req.getParameter("pushDate");
        String work = req.getParameter("work");

        UtilJdbc utilJdbc = new UtilJdbc();

        boolean flag=utilJdbc.insertPushWork(workName,pushDate,work);
        List<Push_work> list2=utilJdbc.PushedWork();
        if(flag){
            req.setAttribute("list2",list2);
            req.getRequestDispatcher("/LoginPag/PushWork.jsp").forward(req,resp);
//            resp.sendRedirect("/LoginPag/PushWork.jsp");

        }else {
//            resp.sendRedirect("/LoginPag/AddWorks.jsp");
            req.getRequestDispatcher("/LoginPag/AddWorks.jsp").forward(req,resp);
        }
    }
}
